/*******************************************************************************
*                                    ZLG
*                         ----------------------------
*                         innovating embedded platform
*
* Copyright (c) 2001-2021 Guangzhou ZHIYUAN Electronics Co., Ltd.
* All rights reserved.
*
* Contact information:
* web site:    https://www.zlg.cn
*******************************************************************************/
#ifndef __HC32F4A0_REGS_USART_H
#define __HC32F4A0_REGS_USART_H

#ifdef __cplusplus
extern "C" {
#endif  /* __cplusplus*/
#include <stdio.h>
#include "hc32f4a0_regs_base.h"

/* \brief USART 控制寄存器1位定义 */
#define USART_CR1_RTOE_POS          (0U)
#define USART_CR1_RTOE              (0x00000001UL)
#define USART_CR1_RTOIE_POS         (1U)
#define USART_CR1_RTOIE             (0x00000002UL)
#define USART_CR1_RE_POS            (2U)
#define USART_CR1_RE                (0x00000004UL)
#define USART_CR1_TE_POS            (3U)
#define USART_CR1_TE                (0x00000008UL)
#define USART_CR1_SLME_POS          (4U)
#define USART_CR1_SLME              (0x00000010UL)
#define USART_CR1_RIE_POS           (5U)
#define USART_CR1_RIE               (0x00000020UL)
#define USART_CR1_TCIE_POS          (6U)
#define USART_CR1_TCIE              (0x00000040UL)
#define USART_CR1_TXEIE_POS         (7U)
#define USART_CR1_TXEIE             (0x00000080UL)
#define USART_CR1_PS_POS            (9U)
#define USART_CR1_PS                (0x00000200UL)    /* 校验位,0:偶校验;1:奇校验*/
#define USART_CR1_PCE_POS           (10U)
#define USART_CR1_PCE               (0x00000400UL)    /* 校验使能位,0:无校验;1:校验*/
#define USART_CR1_M_POS             (12U)
#define USART_CR1_M                 (0x00001000UL)    /* 数据位长度,0:8位;1:9位*/
#define USART_CR1_OVER8_POS         (15U)
#define USART_CR1_OVER8             (0x00008000UL)    /* UART 过采样模式,0:16位,1:8位*/
#define USART_CR1_CPE_POS           (16U)
#define USART_CR1_CPE               (0x00010000UL)
#define USART_CR1_CFE_POS           (17U)
#define USART_CR1_CFE               (0x00020000UL)
#define USART_CR1_CORE_POS          (19U)
#define USART_CR1_CORE              (0x00080000UL)
#define USART_CR1_CRTOF_POS         (20U)
#define USART_CR1_CRTOF             (0x00100000UL)
#define USART_CR1_CBE_POS           (21U)
#define USART_CR1_CBE               (0x00200000UL)
#define USART_CR1_CWKUP_POS         (22U)
#define USART_CR1_CWKUP             (0x00400000UL)
#define USART_CR1_CLBD_POS          (23U)
#define USART_CR1_CLBD              (0x00800000UL)
#define USART_CR1_MS_POS            (24U)
#define USART_CR1_MS                (0x01000000UL)
#define USART_CR1_ML_POS            (28U)
#define USART_CR1_ML                (0x10000000UL)
#define USART_CR1_FBME_POS          (29U)
#define USART_CR1_FBME              (0x20000000UL)
#define USART_CR1_NFE_POS           (30U)
#define USART_CR1_NFE               (0x40000000UL)
#define USART_CR1_SBS_POS           (31U)
#define USART_CR1_SBS               (0x80000000UL)

/* \brief USART 控制寄存器2位定义  */
#define USART_CR2_MPE_POS           (0U)
#define USART_CR2_MPE               (0x00000001UL)
#define USART_CR2_WKUPIE_POS        (1U)
#define USART_CR2_WKUPIE            (0x00000002UL)
#define USART_CR2_BEIE_POS          (2U)
#define USART_CR2_BEIE              (0x00000004UL)
#define USART_CR2_BEE_POS           (3U)
#define USART_CR2_BEE               (0x00000008UL)
#define USART_CR2_LBDIE_POS         (4U)
#define USART_CR2_LBDIE             (0x00000010UL)
#define USART_CR2_LBDL_POS          (5U)
#define USART_CR2_LBDL              (0x00000020UL)
#define USART_CR2_SBKL_POS          (6U)
#define USART_CR2_SBKL              (0x000000C0UL)
#define USART_CR2_SBKL_0            (0x00000040UL)
#define USART_CR2_SBKL_1            (0x00000080UL)
#define USART_CR2_WKUPE_POS         (8U)
#define USART_CR2_WKUPE             (0x00000100UL)
#define USART_CR2_CLKC_POS          (11U)
#define USART_CR2_CLKC              (0x00001800UL)
#define USART_CR2_CLKC_0            (0x00000800UL)
#define USART_CR2_CLKC_1            (0x00001000UL)
#define USART_CR2_STOP_POS          (13U)
#define USART_CR2_STOP              (0x00002000UL)     /* 停止位设置位,0:1停止位;1:2停止位*/
#define USART_CR2_LINEN_POS         (14U)
#define USART_CR2_LINEN             (0x00004000UL)
#define USART_CR2_SBK_POS           (16U)
#define USART_CR2_SBK               (0x00010000UL)
#define USART_CR2_SBKM_POS          (17U)
#define USART_CR2_SBKM              (0x00020000UL)

/* \brief USART 控制寄存器3位定义   */
#define USART_CR3_HDSEL_POS         (3U)
#define USART_CR3_HDSEL             (0x00000008UL)
#define USART_CR3_LOOP_POS          (4U)
#define USART_CR3_LOOP              (0x00000010UL)
#define USART_CR3_SCEN_POS          (5U)
#define USART_CR3_SCEN              (0x00000020UL)
#define USART_CR3_RTSE_POS          (8U)
#define USART_CR3_RTSE              (0x00000100UL)
#define USART_CR3_CTSE_POS          (9U)
#define USART_CR3_CTSE              (0x00000200UL)
#define USART_CR3_BCN_POS           (21U)
#define USART_CR3_BCN               (0x00E00000UL)
#define USART_CR3_BCN_0             (0x00200000UL)
#define USART_CR3_BCN_1             (0x00400000UL)
#define USART_CR3_BCN_2             (0x00800000UL)

/* \brief USART 预分频寄存器位定义 */
#define USART_PR_PSC_POS            (0U)
#define USART_PR_PSC                (0x00000003UL)
#define USART_PR_PSC_0              (0x00000001UL)
#define USART_PR_PSC_1              (0x00000002UL)
#define USART_PR_LBMPSC_POS         (2U)
#define USART_PR_LBMPSC             (0x0000000CUL)
#define USART_PR_LBMPSC_0           (0x00000004UL)
#define USART_PR_LBMPSC_1           (0x00000008UL)

/* \brief USART 波特率寄存器位定义 */
#define USART_BRR_DIV_FRACTION_POS  (0U)
#define USART_BRR_DIV_FRACTION      (0x0000007FUL)
#define USART_BRR_DIV_INTEGER_POS   (8U)
#define USART_BRR_DIV_INTEGER       (0x0000FF00UL)

/* \brief USART 状态寄存器位定义  */
#define USART_SR_PE_POS             (0U)
#define USART_SR_PE                 (0x00000001UL)
#define USART_SR_FE_POS             (1U)
#define USART_SR_FE                 (0x00000002UL)
#define USART_SR_ORE_POS            (3U)
#define USART_SR_ORE                (0x00000008UL)
#define USART_SR_BE_POS             (4U)
#define USART_SR_BE                 (0x00000010UL)
#define USART_SR_RXNE_POS           (5U)
#define USART_SR_RXNE               (0x00000020UL)
#define USART_SR_TC_POS             (6U)
#define USART_SR_TC                 (0x00000040UL)
#define USART_SR_TXE_POS            (7U)
#define USART_SR_TXE                (0x00000080UL)
#define USART_SR_RTOF_POS           (8U)
#define USART_SR_RTOF               (0x00000100UL)
#define USART_SR_WKUP_POS           (9U)
#define USART_SR_WKUP               (0x00000200UL)
#define USART_SR_LBD_POS            (10U)
#define USART_SR_LBD                (0x00000400UL)
#define USART_SR_MPB_POS            (16U)
#define USART_SR_MPB                (0x00010000UL)

/* \brief USART 数据寄存器位定义 */
#define USART_DR_TDR_POS            (0U)
#define USART_DR_TDR                (0x000001FFUL)
#define USART_DR_MPID_POS           (9U)
#define USART_DR_MPID               (0x00000200UL)
#define USART_DR_RDR_POS            (16U)
#define USART_DR_RDR                (0x01FF0000UL)

/* \brief HC32F4A0 USART寄存器*/
struct hc32f4a0_usart_reg {
    volatile uint32_t SR;
    volatile uint32_t DR;
    volatile uint32_t BRR;
    volatile uint32_t CR1;
    volatile uint32_t CR2;
    volatile uint32_t CR3;
    volatile uint32_t PR;
    volatile uint32_t LBMC;
};

#define HC32F4A0_USART1    ((struct hc32f4a0_usart_reg *)HC32F4A0_USART1_BASE)
#define HC32F4A0_USART2    ((struct hc32f4a0_usart_reg *)HC32F4A0_USART2_BASE)
#define HC32F4A0_USART3    ((struct hc32f4a0_usart_reg *)HC32F4A0_USART3_BASE)
#define HC32F4A0_USART4    ((struct hc32f4a0_usart_reg *)HC32F4A0_USART4_BASE)
#define HC32F4A0_USART5    ((struct hc32f4a0_usart_reg *)HC32F4A0_USART5_BASE)
#define HC32F4A0_USART6    ((struct hc32f4a0_usart_reg *)HC32F4A0_USART6_BASE)
#define HC32F4A0_USART7    ((struct hc32f4a0_usart_reg *)HC32F4A0_USART7_BASE)
#define HC32F4A0_USART8    ((struct hc32f4a0_usart_reg *)HC32F4A0_USART8_BASE)
#define HC32F4A0_USART9    ((struct hc32f4a0_usart_reg *)HC32F4A0_USART9_BASE)
#define HC32F4A0_USART10   ((struct hc32f4a0_usart_reg *)HC32F4A0_USART10_BASE)

#ifdef __cplusplus
}
#endif  /* __cplusplus  */

#endif

